<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>签到</title>
    <link href="/css/style.css" rel="stylesheet" type="text/css"/>
    <link href="/css/reset.css" rel="stylesheet" type="text/css"/>
    <link href="/css/supersized.css" rel="stylesheet" type="text/css"/>

    <script src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
    <script type="text/javascript" src="/js/pupop.js"></script>
    <script type="text/javascript" src="/js/jquery-1.8.2.min.js"></script>
    <script type="text/javascript" src="/js/supersized.3.2.7.min.js"></script>
    <script type="text/javascript" src="/js/supersized-init.js"></script>
    <script type="text/javascript" src="/js/scripts.js"></script>

    <script>
        function success(msg) {
            pupopTip('200px', '120px', '&nbsp;' + msg);
        }
        function lose(msg) {
            pupopTip('200px', '120px', '&nbsp;' + msg);
        }
        function lose_1() {
            pupopTip('200px', '120px', '&nbsp;&nbsp;&nbsp;&nbsp;签到失败<br>您输入的名字有误');
        }
    </script>
    <script>
        $(function () {
            var teacher = getUrlParms("teacherName");
            window.history.pushState(null, null,teacher);

        });
    </script>
    <script>

        function getUrlParms(name) {
            var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
            var r = window.location.search.substr(1).match(reg);
            if (r != null)
                return unescape(r[2]);
            return null;
        }

        function doSignIn() {
            var stu_id = $('#stu_id').val();
            if (stu_id.length != 13) {
                lose("您输入的学号有误");
                $(document).bind("click", function (e) {
                    $('div').closest('.pupopBox').each(function () {
                        if (e.target == this) {
                            $(this).remove();
                        }
                    });
                });
            } else {
                var name = $('#name').val();
//                var teacherName = getUrlParms("teacherName");
//                var teacherName = window.location.pathname;
                var teacherName = window.location.pathname.replace('/',"");
//                console.log(teacherName);
//                var teacherName = location.search.replace('?',"");
                console.log(teacherName);
                var url = window.location.search;
                if (name.length >= 2 && name.length <= 5) {
                    $.ajax({
                        type: "POST",
                        url: "/signInOf",
                        dataType: 'json',
                        data: {
                            'stuId': stu_id,
                            'name': name,
                            'teacherName': teacherName
                        },
                        success: function (data) {
//                        console.log(data);
                            var msg = data.msg;
                            if (data.code == 1) {
                                lose(msg);
                            } else {
                                success(msg);
                            }
                        }
                    });
                } else {
                    lose_1();
                    setTimeout(function () {
                        window.location.href = '/signIn'
                    }, 500);
                }

            }


        }
    </script>
</head>
<body>
<br><br><br><br><br><br><br><br><br><br>
<h1 align="center">签到</h1>

<div id="loginDiv">
    <input type="text" class="form-control" id="stu_id" placeholder="请输入学号" autocomplete="off">
    <br>
    <input type="text" class="form-control" id="name" placeholder="请输入姓名" autocomplete="off">
</div>
<input type="submit" value="签到" class="btn btn-primary" onclick="doSignIn()">
</body>
</html>